package com.lao.demo.strategymode.controller;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

/**
 * @Author: xuchao
 * @Description:
 * @Date: 2021/5/13 16:18
 */
public class MyMD5 {
    //获取字符串的MD5串
    public static String Md5(//
                             String plainText               //原字符串
    ) {
        if (plainText == null) {
            return null;
        }
        StringBuffer buf = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            md.reset();
            byte b[] = md.digest();
            int i;
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0) {
                    i += 256;
                }
                if (i < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(i));
            }
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return buf.toString();
    }

    public static void main(String[] args) {
        String s = Md5("{\"customerName\":\"dive_13071339\",\"encryptNum\":\"0a0bNej/oiQy0cXuqiaOaMkBqA==0c\",\"encryptType\":1}");
        System.out.println(s);
    }
}
